package cn.fanqinghong.ymcc.controller;

import cn.fanqinghong.ymcc.doc.CourseDoc;
import cn.fanqinghong.ymcc.dto.CourseSearchDto;
import cn.fanqinghong.ymcc.result.JSONResult;
import cn.fanqinghong.ymcc.result.PageList;
import cn.fanqinghong.ymcc.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * FAN
 * 2022/7/24  15:16
 */
@RestController
public class CourseESController {

    @Autowired
    private ISearchService searchService;

    @PostMapping("/saveCourse")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        searchService.saveCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/deleteCourse")
    public JSONResult deleteCourse(@RequestBody CourseDoc doc){
        searchService.deleteCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/course/search")
    public PageList<CourseDoc> search(@RequestBody CourseSearchDto doc){

        return searchService.search(doc);
    }

}
